<?php

/**
 * @version		1.5.x
 * @package		JoomlaVi Project
 * @copyright	Copyright (C) JoomlaVi. All rights reserved.
 * @license		Proprietary - JoomlaVi Club members only
 * @email       info@joomlavi.com 
 */

class JVSEO {
	
	public static $links = array ();
	public static $images = array ();
	public static $input = array ();
	public static $spectag = array ();
    
	/**
	 * JVKeySeo
     * 
	 * @param  string $content
     * @param  array  $key     
	 * @return string component 
	 */
	function JVKeySeo($content, $key) {
	    //$content = preg_replace ( array ("/\t/","/\r\n/" ), '', $content );
		$cpn = preg_replace_callback ( '/<img\b[^>]*\/>/', array ('JVSEO', 'removeImage' ), $content );
		$cpn = preg_replace_callback ( '/<a\b[^>]*>(.*?)<\/a>/', array ('JVSEO', 'removeLink' ), $cpn );
		$cpn = preg_replace_callback ( array ('/<input\b[^>]*\/>/' ), array ('JVSEO', 'removeInput' ), $cpn );
		$cpn = preg_replace_callback ( array ('/<h.\b[^>]*>(.*?)<\/h.>/', '/<span\b[^>]*>(.*?)<\/span>/' ), array ('JVSEO', 'removeSpectag' ), $cpn );
		
        foreach ( $key as $key ) {
			$key = explode ( '|', $key );
			$link =& $key[1] ? $key[1] : '';
			$keyword = $key [0];
			
			$cpn = str_ireplace ( $keyword, "<a href='$link' title='$link'>$keyword</a>", $cpn );
		}
		
        foreach ( JVSEO::$spectag as $key => $spectag ) {
		  $cpn = str_ireplace ( $key, $spectag, $cpn );
		}
        
        foreach ( JVSEO::$input as $key => $input ) {
		  $cpn = str_ireplace ( $key, $input, $cpn );
		}
        
		foreach ( JVSEO::$links as $key => $links ) {
			$cpn = str_ireplace ( $key, $links, $cpn );
		}
		
		foreach ( JVSEO::$images as $key => $images ) {
			$cpn = str_ireplace ( $key, $images, $cpn );
		}
        
		return $cpn;
	
	}
    
    /**
	 * Remove link
     * 
	 * @param  string $match    
	 * @return string the link of the removed link 
	 */	
	function removeLink($match) {
		static $link = 0;
		JVSEO::$links += array ("{jvl{$link}}" => $match [0] );
		return "{jvl" . $link ++ . "}";
	}
	
    /**
	 * Remove image
     * 
	 * @param  string $match    
	 * @return string the link of the removed image  
	 */	
	function removeImage($match) {
		static $image = 0;
		JVSEO::$images += array ("{jvimg{$image}}" => $match [0] );
		return "{jvimg" . $image ++ . "}";
	}
	
    /**
	 * Remove input
     * 
	 * @param  string $match    
	 * @return string the link of the removed input
	 */	
	function removeInput($match) {
		static $input = 0;
		JVSEO::$input += array ("{jvinput{$input}}" => $match [0] );
		return "{jvinput" . $input ++ . "}";
	}
    
    /**
	 * Remove special tag
     * 
	 * @param  string $match    
	 * @return string the link of the removed tag
	 */	
    function removeSpectag($match) {
		static $spectag = 0;
		JVSEO::$spectag += array ("{spectag{$spectag}}" => $match [0] );
		return "{spectag" . $spectag ++ . "}";
	}
}
